﻿<?php 
//意见反馈接口

include("conn.php");
mysql_query('SET NAMES UTF8'); 

class MyPrizeBean {
	public $code;

	function __construct($fulse)
	{
		$this->code = $fulse;
	}
}

if($_GET['userid'] != "" || $_GET['shopid'] != null) {    
	$state = 1;
	$date = date("Y-m-d h:i:s");
	$str = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $_REQUEST['content']);//转义表情 （输入法表情输入时使用）
	$zhuan = addslashes($str);//转义

	$shopid = is_null($_GET['shopid'])?'0':$_GET['shopid'];
	$userid = is_null($_GET['userid'])?'0':$_GET['userid'];

	if($shopid != 0) {
		$sql = "SELECT name FROM shop WHERE shopid = $shopid";
		$data = mysql_fetch_assoc(mysql_query($sql));
	} else {
		$sql = "SELECT niname FROM user WHERE userid = $userid";
		$data = mysql_fetch_assoc(mysql_query($sql));
		$data['name'] = $data['niname'];
		unset($data['niname']);
	}

	//意见插入表里
	$sql = "INSERT INTO feedback(userid,content,addtime,shopid,name) VALUES ('" . $userid . "','" . $zhuan . "','" . $date . "','" . $shopid . "','" . $data['name'] . "')";
	$srat = mysql_query($sql);
	//end

	if($srat == true) {
		$der = 200;
	}  else {
   		$der = 500;
	}
} else {
	$der = 500;
}

$prize = new MyPrizeBean($der);
echo json_encode($prize);